package cn.fz.ssedemo.service;

import cn.fz.ssedemo.dao.AlarmMapper;
import cn.fz.ssedemo.domain.dto.AlarmEventDto;
import cn.fz.ssedemo.domain.po.AlarmEntity;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class AlarmService extends ServiceImpl<AlarmMapper, AlarmEntity> implements IService<AlarmEntity> {
    private final PublisherMessageService publisherMessageService;

    public void saveAlarm(AlarmEventDto alarmEventDto) {
        try {
            AlarmEntity alarmEntity = BeanUtil.copyProperties(alarmEventDto, AlarmEntity.class);
            save(alarmEntity);
            publisherMessageService.publish(BeanUtil.beanToMap(alarmEntity));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
